package com.wl.application.interceptor;

import com.wl.application.common.all.ResultEnum;
import com.wl.application.common.childException.BusinessException;
import com.wl.application.controller.AllotController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author wl
 * @version 1.0
 * @date 2022/6/25
 * @description: 权限拦截器
 */
@Component
@Slf4j
public class PowerInterceptor implements HandlerInterceptor {

    @Autowired
    private AllotController allotController;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //验证当前用户是否有该权限
        if (!allotController.checkPower()) {
            throw new BusinessException(ResultEnum.NO_POWER.getCode(),ResultEnum.NO_POWER.getMsg());
        }
        return true;
    }
}
